package com.example.wlzz.controller;

import com.example.wlzz.entity.UpdateApp;
import com.example.wlzz.repository.BannerRepository;
import com.example.wlzz.repository.NoticeRepository;
import com.example.wlzz.repository.UpdateAppRepository;
import com.example.wlzz.utils.ResultVOUtil;
import com.example.wlzz.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/wlzzSystem")
@Slf4j
@Api(tags = "系统模块(banner图,公告等等)")
public class SystemController {
    @Autowired
    private BannerRepository bannerRepository;  //无任何业务逻辑不中转service
    @Autowired
    private NoticeRepository noticeRepository; //无任何业务逻辑不中转service
    @Autowired
    private UpdateAppRepository updateAppRepository;
    @GetMapping("/getBanner")
    @ApiOperation("获取轮播图")
    public ResultVO getBanner(){
        return ResultVOUtil.success(bannerRepository.findByFlag(0));
    }
    @GetMapping("/getNotice")
    @ApiOperation("获取公告")
    public ResultVO getNotice(){
        return ResultVOUtil.success(noticeRepository.findByFlag(0));
    }
    @PostMapping("/updateBean")
    @ApiOperation("获取app最新版本")
    public ResultVO updateBean(@RequestParam("channel") String channel){
        UpdateApp updateApp =  updateAppRepository.findById(1);
        Map<String,Object> map = new HashMap<>();
        map.put("id",String.valueOf(updateApp.getId()));
        map.put("name",updateApp.getName());
        map.put("path",updateApp.getPath());
        map.put("remark",updateApp.getRemark());
        map.put("create_at",String.valueOf(updateApp.getCreate_at().getTime()));
        map.put("version",updateApp.getVersion());
        map.put("force",updateApp.getForce());
        return ResultVOUtil.success(map);
    }

}
